<template>
  <div>
    <el-form :inline="true" :model="formInline" class="demo-form-inline">
      <el-form-item label="逾期金额">
        <el-input
          v-model="formInline.overdueAmount"
          placeholder="逾期金额"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="tableData" style="width: 100%">
      <el-table-column label="主键" width="80">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.id }}</span>
        </template>
      </el-table-column>
      <el-table-column label="合同" width="180">
        <template slot-scope="scope">
          <el-popover trigger="hover" placement="top">
            <p>信用代码: {{ scope.row.contractInfo }}</p>
            <p>电话: {{ scope.row.contractInfo }}</p>
            <div slot="reference" class="name-wrapper">
              <el-tag size="medium">{{ scope.row.contractInfo }}</el-tag>
            </div>
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column label="逾期状态" width="180">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.repaymentStatus }}</span>
        </template>
      </el-table-column>
      <el-table-column label="还款期次" width="180">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.repaymentPeriod }}</span>
        </template>
      </el-table-column>
      <el-table-column label="还款金额" width="180">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.overdueAmount }}</span>
        </template>
      </el-table-column>

      <el-table-column label="操作" width="180">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.$index, scope.row)"
            >查看详情</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <div class="block">
      <span class="demonstration">完整功能</span>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="responseResult.pageNumber"
        :page-sizes="[5, 5, 5, 5]"
        :page-size="responseResult.page_SIZE"
        layout="total, sizes, prev, pager, next, jumper"
        :total="responseResult.total"
      >
      </el-pagination>
    </div>

    <el-dialog
      title="详情"
      :visible.sync="dialogTableVisible"
      style="width=1000px"
    >
      <el-table :data="dialogResponseResult.products">
        <el-table-column property="id" label="主键"></el-table-column>
        <el-table-column
          property="repaymentDate"
          label="应该还款日期"
        ></el-table-column>
        <el-table-column
          property="repaymentPeriod"
          label="周期"
        ></el-table-column>
        <el-table-column
          property="principalRepayable"
          label="应还本金"
          width="150"
        ></el-table-column>
        <el-table-column
          property="interestRepayable"
          label="应还利息"
        ></el-table-column>
        <el-table-column
          property="totalRepayment"
          label="总共应还金额"
        ></el-table-column>
        <el-table-column
          property="actualRepaymentAmount"
          label="实际还款金额"
        ></el-table-column>
        <el-table-column
          property="actualRepaymentDate"
          label="实际还款日期"
        ></el-table-column>
        <el-table-column label="操作" width="180">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="danger"
              v-if="scope.row.actualRepaymentAmount != scope.row.totalRepayment"
              @click="handleRepayment(scope.$index, scope.row)"
              >立即还款</el-button
            >
            <el-button
              size="mini"
              class="del-com"
              type="primary"
              v-if="scope.row.actualRepaymentAmount == scope.row.totalRepayment"
              >本期已还</el-button
            >
          </template>
        </el-table-column>
      </el-table>

      <div class="block">
        <span class="demonstration">完整功能</span>
        <el-pagination
          @current-change="dialogHandleCurrentChange"
          :current-page="dialogResponseResult.pageNumber"
          :page-sizes="[5, 5, 5, 5]"
          :page-size="dialogResponseResult.page_SIZE"
          layout="total, sizes, prev, pager, next, jumper"
          :total="dialogResponseResult.total"
        >
        </el-pagination>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      // <<< 查询条件 <<<
      formInline: {
        overdueAmount: "",
      },
      // >>> 查询条件 >>>

      // <<< 遍历表格 <<<
      tableData: [
        {
          id: 4,
          contractInfo: 2,
          repaymentStatus: "逾期",
          repaymentPeriod: 2,
          overdueAmount: 2000,
        },
        {
          id: 5,
          contractInfo: 2,
          repaymentStatus: "逾期",
          repaymentPeriod: 2,
          overdueAmount: 2000,
        },
      ],
      // >>> 遍历表格 >>>

      // <<< 响应结果 后端的pagebean <<
      responseResult: {
        code: 200,
        status: "HAVE_PERMS",
        message: "select ok",
        data: {
          total: 2,
          pageNumber: 1,
          totalPage: 1,
          startIndex: 1,
          endIndex: 1,
          products: [
            {
              id: 4,
              contractInfo: 2,
              repaymentStatus: "逾期",
              repaymentPeriod: 2,
              overdueAmount: 2000,
            },
            {
              id: 5,
              contractInfo: 2,
              repaymentStatus: "逾期",
              repaymentPeriod: 2,
              overdueAmount: 2000,
            },
          ],
          page_SIZE: 5,
        },
      },
      // >>> 响应结果 >>>

      // <<< dialog <<<
      dialogTableVisible: false,
      manageId: 1,
      // <<< 响应结果 后端的pagebean <<
      dialogResponseResult: {
        endIndex: 3,
        pageNumber: 1,
        page_SIZE: 5,
        products: [
          {
            id: 1,
            manageInfo: 1,
            repaymentDate: null,
            repaymentPeriod: 1,
            principalRepayable: 1000,
            interestRepayable: 10,
            totalRepayment: 1010,
            actualRepaymentAmount: 1000,
            actualRepaymentDate: "2021-11-16T07:06:43.000+00:00",
          },
          {
            id: 2,
            manageInfo: 1,
            repaymentDate: "3921-11-19T18:00:00.000+00:00",
            repaymentPeriod: 2,
            principalRepayable: 1000,
            interestRepayable: 10,
            totalRepayment: 1010,
            actualRepaymentAmount: 1000,
            actualRepaymentDate: "2021-11-16T07:08:07.000+00:00",
          },
        ],
        startIndex: 1,
        total: 14,
        totalPage: 3,
      },
      // >>> 响应结果 >>>
      // >>> dialog  >>>
    };
  },
  created() {
    this.onSubmit();
  },
  methods: {
    onSubmit() {
      // 先把分页重置
      let url = "http://localhost:9823/repaymentOverdue/selectall/";
      url = url + "1" + "?" + "repaymentStatus=逾期&overdueAmount=" + this.formInline.overdueAmount;
      //console.log(url);
      this.$axios.get(url).then((resp) => {
        // 得到后端传的pageBean
        this.responseResult = resp.data.data;
        this.tableData = resp.data.data.products;
        console.log(this.responseResult);
      });
      //console.log("submit!");
    },
    handleEdit(index, row) {
      this.dialogTableVisible = true;
      // console.log(index);
      // console.log(row);
      let url = "http://localhost:9823/registration/selectall/1?manageInfo=";
      // url 拼接
      url = url + row.id;
      this.manageId = row.id;
      //console.log(url);
      this.$axios.get(url).then((resp) => {
        // 得到后端传的pageBean
        this.dialogResponseResult = resp.data.data;
        // console.log(this.dialogResponseResult);
      });
    },

    // <<< dialog <<<
    handleRepayment(index, row) {
      // console.log(index, row);
    },
    handleSizeChange(val) {
      //console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      
      let url = "http://localhost:9823/repaymentOverdue/selectall/";
      url = url + val + "?" + "repaymentStatus=逾期&overdueAmount=" + this.formInline.overdueAmount;

      //console.log(url);
      this.$axios.get(url).then((resp) => {
        // 得到后端传的pageBean
        this.responseResult = resp.data.data;
        this.tableData = resp.data.data.products;
        console.log(this.responseResult);
      });
    },
    dialogHandleCurrentChange(val) {
      let url =
        "http://localhost:9823/registration/selectall/" + val + "?manageInfo=";
      // url 拼接
      url = url + this.manageId;
      //console.log(url);
      this.$axios.get(url).then((resp) => {
        // 得到后端传的pageBean
        this.dialogResponseResult = resp.data.data;
        //console.log(this.dialogResponseResult);
      });
    },
    // >>> dialog >>>
  },
};
</script>
    
<style>
</style>